/**
 * 查看介绍
 */
function introduceChess() {
    if (DATA_CURRENT_SELECTED_CHESS == null) {
        return;
    }
    // 创建介绍内容
    const selectedChess = DATA_CHESS[DATA_CURRENT_SELECTED_CHESS];
    const config = selectedChess.config;
    const introContent = document.createElement('div');
    const piece = selectedChess.piece;
    introContent.id = "panel-introduce-content";
    introContent.style.marginLeft = '15px';
    introContent.innerHTML = '<h2 class="panel-introduce-title">棋子介绍：'+piece.dataset.type+'</h2>'
        +'<div style="line-height: 1.5; color: #444;">'
        +getActionDescription(config,"passRiver")
        +getActionDescription(config,"outOfPalace")
        +getActionDescription(config,"moveBeforeRiver")
        +getActionDescription(config,"moveAfterRiver")
        +getActionDescription(config,"captureScreen")
        +getActionDescription(config,"captureBeforeRiver")
        +getActionDescription(config,"captureAfterRiver")
        +'<p><strong></strong></p>'
        +'</div>';
    // 检查弹窗是否已创建，避免重复创建
    let overlay = document.getElementById('chessIntroOverlay');
    if (overlay) {
        document.getElementById("panel-introduce-content").remove();
        // 组装弹窗
        const modal = document.getElementById("panel-introduce-panel");
        modal.appendChild(introContent);
        overlay.style.display = 'flex';
        document.body.style.overflow = 'hidden';
    }
    else {
        // 创建遮罩层
        overlay = document.createElement('div');
        overlay.id = 'chessIntroOverlay';
        overlay.classList.add("panel-introduce-overlay");
        // 创建弹窗主体（640×480）
        const modal = document.createElement('div');
        modal.classList.add("panel-introduce-panel");
        modal.id = "panel-introduce-panel";
        // 创建关闭按钮
        const closeBtn = document.createElement('span');
        closeBtn.textContent = '×';
        closeBtn.classList.add("panel-introduce-close");
        // 关闭逻辑
        function hideModal() {
            overlay.style.display = 'none';
            document.body.style.overflow = '';
        }
        // 绑定关闭事件
        closeBtn.onclick = hideModal;
        overlay.onclick = (e) => {
            if (e.target === overlay) hideModal();
        };
        document.addEventListener('keydown', (e) => {
            if (e.key === 'Escape' && overlay.style.display === 'flex') {
                hideModal();
            }
        });
        // 组装弹窗
        modal.appendChild(introContent);
        modal.appendChild(closeBtn);
        overlay.appendChild(modal);
        document.body.appendChild(overlay);
        document.body.style.overflow = 'hidden';
    }
}
function getActionDescription(config,contentKey) {
    let contentInfo = config[contentKey];
    let resultContent = '';
    switch (contentKey) {
        case "moveBeforeRiver":
            if (contentInfo == null || contentInfo.length === 0) {
                break;
            }
            resultContent = resultContent
                +'<div>'
                +'<p><strong>移动方式(过河前)</strong></p>'
                +getChangePositionDescription(contentInfo)
                +'</div>';
            break;
        case "moveAfterRiver":
            if (contentInfo == null || contentInfo.length === 0) {
                break;
            }
            resultContent = resultContent
                +'<div>'
                +'<p><strong>移动方式(过河后)</strong></p>'
                +getChangePositionDescription(contentInfo)
                +'</div>';
            break;
        case "captureBeforeRiver":
            if (contentInfo == null || contentInfo.length === 0) {
                break;
            }
            resultContent = resultContent
                +'<div>'
                +'<p><strong>吃子方式(过河前)</strong></p>'
                +getChangePositionDescription(contentInfo)
                +'</div>';
            break;
        case "captureAfterRiver":
            if (contentInfo == null || contentInfo.length === 0) {
                break;
            }
            resultContent = resultContent
                +'<div>'
                +'<p><strong>吃子方式(过河后)</strong></p>'
                +getChangePositionDescription(contentInfo)
                +'</div>';
            break;
        case "outOfPalace":
            if (contentInfo == null) {
                contentInfo = true;
            }
            if (!contentInfo) {
                resultContent = resultContent
                    +'<div>'
                    +'<p><strong>无法离开九宫格。</strong></p>'
                    +'</div>';
            }
            break;
        case "passRiver":
            if (contentInfo == null) {
                contentInfo = true;
            }
            if (!contentInfo) {
                resultContent = resultContent
                    +'<div>'
                    +'<p><strong>无法过河。</strong></p>'
                    +'</div>';
            }
            break;
        case "captureScreen":
            if (contentInfo == null) {
                contentInfo = false;
            }
            if (contentInfo) {
                resultContent = resultContent
                    +'<div>'
                    +'<p><strong>吃子需要支撑点。</strong></p>'
                    +'</div>';
            }
            break;
    }
    return resultContent;
}
function getChangePositionDescription(actionList) {
    let ul = '<ul>';
    for (let i = 0; i < actionList.length; i++) {
        let action = actionList[i];
        let absolute = action.absolute === true;
        let x = action.x;
        let colDirection = x===0?'':('向'+(x>0?('右'+(absolute?'固定':'最远')+x+'格'):('左'+(absolute?'固定':'最远')+(0-x)+'格')));
        let y = action.y;
        let rowDirection = y===0?'':('向'+(y>0?('前'+(absolute?'固定':'最远')+y+'格'):('后'+(absolute?'固定':'最远')+(0-y)+'格')));
        let splitPot = (colDirection!==''&&rowDirection!=='')?'、':'';
        let targetPosition = colDirection+splitPot+rowDirection;
        targetPosition = targetPosition===''?'':(targetPosition+'。')
        let bx = action.bx || 0;
        let colBlockDirection = bx===0?'':(bx>0?('右侧'+bx+'格'):('左侧'+(0-bx)+'格'));
        let by = action.by || 0;
        let rowBlockDirection = by===0?'':(by>0?('前方'+by+'格'):('后方'+(0-by)+'格'));
        let blockPot = (colBlockDirection!==''&&rowBlockDirection!=='')?'、':'';
        let blockPosition = colBlockDirection+blockPot+rowBlockDirection;
        blockPosition = blockPosition === '' ? '' : ('但如果棋子的“'+blockPosition+'”处存在棋子，则无法移动。');
        ul = ul+'<li>'
            +targetPosition
            +blockPosition
            +'</li>';
    }
    ul = ul + '</ul>';
    return ul;
}